home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / clipcu1a / trapmous.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1999-10-16  |  4.9 KB  |  169 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTrapMouse 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "ClipCursor Demo"
  5.    ClientHeight    =   1800
  6.    ClientLeft      =   1980
  7.    ClientTop       =   2520
  8.    ClientWidth     =   4590
  9.    Icon            =   "TrapMouse.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   1800
  14.    ScaleWidth      =   4590
  15.    Begin VB.CommandButton cmdCommandTrap 
  16.       Caption         =   "Trap To Command Button"
  17.       Height          =   735
  18.       Left            =   120
  19.       TabIndex        =   3
  20.       Top             =   840
  21.       Width           =   1215
  22.    End
  23.    Begin VB.Frame fraTrap 
  24.       Caption         =   "Frame"
  25.       Height          =   1575
  26.       Left            =   1560
  27.       TabIndex        =   1
  28.       Top             =   120
  29.       Width           =   2775
  30.       Begin VB.CommandButton cmdFrameTrap 
  31.          Caption         =   "Trap To Frame"
  32.          Height          =   375
  33.          Left            =   1440
  34.          TabIndex        =   2
  35.          Top             =   1080
  36.          Width           =   1215
  37.       End
  38.    End
  39.    Begin VB.CommandButton cmdFormTrap 
  40.       Caption         =   "Trap To Form"
  41.       Height          =   495
  42.       Left            =   120
  43.       TabIndex        =   0
  44.       Top             =   120
  45.       Width           =   1215
  46.    End
  47. Attribute VB_Name = "frmTrapMouse"
  48. Attribute VB_GlobalNameSpace = False
  49. Attribute VB_Creatable = False
  50. Attribute VB_PredeclaredId = True
  51. Attribute VB_Exposed = False
  52. Option Explicit
  53. '''''''''''''''''''''''''''''''''''''''''''''
  54. ' Clip Cursor Demo  by: Steve Weller
  55. ' E-Mail: TheVBFreak13@aol.com
  56. ' Purpose: to demonstrate the ClipCursor API
  57. '  function and its various uses (it can be
  58. '  used with any control as long as left and
  59. '  top are supplied). Also resets the
  60. '  clipping when the program is exited.
  61. ' Date Created: October 16, 1999
  62. Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
  63. Private Type RECT
  64.   Left As Long
  65.   Top As Long
  66.   Right As Long
  67.   Bottom As Long
  68. End Type
  69. Private Sub cmdCommandTrap_Click()
  70. ' trap cursor to command button
  71. Dim Rct As RECT, X%, Y%
  72. X = Screen.TwipsPerPixelX
  73. Y = Screen.TwipsPerPixelY
  74. If cmdCommandTrap.Caption = "Trap To Command Button" Then
  75.   ' values are adjusted so cursor is clipped correctly
  76.   ' DO NOT CHANGE!!
  77.   With Rct
  78.     .Left = ((Me.Left + cmdCommandTrap.Left) / X) + 4
  79.     .Top = ((Me.Top + cmdCommandTrap.Top) / Y) + 24
  80.     .Right = .Left + cmdCommandTrap.Width / X
  81.     .Bottom = (.Top + cmdCommandTrap.Height / Y) - 2
  82.   End With
  83.   cmdFrameTrap.Enabled = False
  84.   cmdFormTrap.Enabled = False
  85.   ClipCursor Rct
  86.   cmdCommandTrap.Caption = "Untrap"
  87.   With Rct
  88.     .Left = 0
  89.     .Top = 0
  90.     .Right = Screen.Width / X
  91.     .Bottom = Screen.Height / Y
  92.   End With
  93.   cmdFrameTrap.Enabled = True
  94.   cmdFormTrap.Enabled = True
  95.   ClipCursor Rct
  96.   cmdCommandTrap.Caption = "Trap To Command Button"
  97. End If
  98. End Sub
  99. Private Sub cmdFormTrap_Click()
  100. ' traps the cursor to the form
  101. Dim Rct As RECT, X%, Y%
  102. X = Screen.TwipsPerPixelX
  103. Y = Screen.TwipsPerPixelY
  104. If cmdFormTrap.Caption = "Trap To Form" Then
  105.   With Rct
  106.     .Left = Me.Left / X
  107.     .Top = Me.Top / Y
  108.     .Right = .Left + Me.Width / X
  109.     .Bottom = .Top + Me.Height / Y
  110.   End With
  111.   cmdFrameTrap.Enabled = False
  112.   cmdCommandTrap.Enabled = False
  113.   ClipCursor Rct
  114.   cmdFormTrap.Caption = "Untrap"
  115.   With Rct
  116.     .Left = 0
  117.     .Top = 0
  118.     .Right = Screen.Width / X
  119.     .Bottom = Screen.Height / Y
  120.   End With
  121.   cmdFrameTrap.Enabled = True
  122.   cmdCommandTrap.Enabled = True
  123.   ClipCursor Rct
  124.   cmdFormTrap.Caption = "Trap To Form"
  125. End If
  126. End Sub
  127. Private Sub cmdFrameTrap_Click()
  128. ' trap cursor to frame
  129. Dim Rct As RECT, X%, Y%
  130. X = Screen.TwipsPerPixelX
  131. Y = Screen.TwipsPerPixelY
  132. If cmdFrameTrap.Caption = "Trap To Frame" Then
  133.   ' values are adjusted so cursor is clipped correctly
  134.   ' DO NOT CHANGE!!
  135.   With Rct
  136.     .Left = ((Me.Left + fraTrap.Left) / X) + 4
  137.     .Top = ((Me.Top + fraTrap.Top) / Y) + 24
  138.     .Right = .Left + fraTrap.Width / X
  139.     .Bottom = (.Top + fraTrap.Height / Y) - 2
  140.   End With
  141.   cmdCommandTrap.Enabled = False
  142.   cmdFormTrap.Enabled = False
  143.   ClipCursor Rct
  144.   cmdFrameTrap.Caption = "Untrap"
  145.   With Rct
  146.     .Left = 0
  147.     .Top = 0
  148.     .Right = Screen.Width / X
  149.     .Bottom = Screen.Height / Y
  150.   End With
  151.   cmdCommandTrap.Enabled = True
  152.   cmdFormTrap.Enabled = True
  153.   ClipCursor Rct
  154.   cmdFrameTrap.Caption = "Trap To Frame"
  155. End If
  156. End Sub
  157. Private Sub Form_Unload(Cancel As Integer)
  158. ' reset the clipped cursor in case a user
  159. ' tries to exit after clicking a "Trap" button
  160. Dim Rct As RECT
  161. With Rct
  162.   .Left = 0
  163.   .Top = 0
  164.   .Right = Screen.Width / Screen.TwipsPerPixelX
  165.   .Bottom = Screen.Height / Screen.TwipsPerPixelY
  166. End With
  167. ClipCursor Rct
  168. End Sub
  169.